package com.youyi.yypermissionlibrary.SDK;

import android.app.AppOpsManager;
import android.app.Application;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Process;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.lkx.liandianqinew.R;
import com.yanzhenjie.permission.runtime.Permission;
import com.youyi.yypermissionlibrary.core.Acp;
import com.youyi.yypermissionlibrary.core.AcpActivity11;
import com.youyi.yypermissionlibrary.core.AcpListener;
import com.youyi.yypermissionlibrary.core.AcpOptions;
import com.youyi.yypermissionlibrary.core.os.SettingPage;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

public class YYPerUtils {
    private static final String CHECK_OP_NO_THROW = "checkOpNoThrow";
    private static final String OP_POST_NOTIFICATION = "OP_POST_NOTIFICATION";
    private static final String TAG = "YYPerUtils";
    public static AcpListener acpListener11;
    private static Dialog dialog;
    private static Context yContext;

    public interface OnClickResult {
        void result(boolean z);
    }

    public static void initContext(Context context) {
        yContext = context;
    }

    public static boolean hasSensors() {
        if (yContext == null) {
            return false;
        }
        return checkHasPermission(Permission.BODY_SENSORS);
    }

    public static boolean hasLocaton() {
        if (yContext == null) {
            return false;
        }
        return checkHasPermission(Permission.ACCESS_COARSE_LOCATION, Permission.ACCESS_FINE_LOCATION);
    }

    public static boolean hasAudio() {
        if (yContext == null) {
            return false;
        }
        return checkHasPermission(Permission.RECORD_AUDIO);
    }

    public static boolean hasSms() {
        if (yContext == null) {
            return false;
        }
        return checkHasPermission(Permission.SEND_SMS);
    }

    public static boolean hasSD() {
        if (yContext == null) {
            return false;
        }
        if (Build.VERSION.SDK_INT >= 30) {
            return Environment.isExternalStorageManager();
        }
        return checkHasPermission(Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE);
    }

    private static boolean hasSDMI() {
        if (yContext == null) {
            return false;
        }
        return checkHasPermission(Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE);
    }

    public static boolean hasImage() {
        if (yContext == null) {
            return false;
        }
        if (Build.VERSION.SDK_INT >= 33) {
            return checkHasPermission("android.permission.READ_MEDIA_IMAGES");
        }
        return true;
    }

    public static boolean hasCamera() {
        if (yContext == null) {
            return false;
        }
        return checkHasPermission(Permission.CAMERA);
    }

    public static boolean hasCallExecute() {
        return checkHasPermission(Permission.READ_PHONE_STATE, Permission.CALL_PHONE, Permission.PROCESS_OUTGOING_CALLS);
    }

    public static void callExecute(final OnPerListener onPerListener) {
        Acp.getInstance(yContext).request(new AcpOptions.Builder().setPermissions(Permission.READ_PHONE_STATE, Permission.CALL_PHONE, Permission.PROCESS_OUTGOING_CALLS).build(), new AcpListener() {
            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass1 */

            @Override // com.youyi.yypermissionlibrary.core.AcpListener
            public void onGranted() {
                
                if (onPerListener != null) {
                    onPerListener.result(true, "");
                }
                YYPerUtils.destroy();
            }

            @Override // com.youyi.yypermissionlibrary.core.AcpListener
            public void onDenied(List<String> list) {
                
                if (onPerListener != null) {
                    onPerListener.result(false, "");
                }
                YYPerUtils.destroy();
            }
        });
    }

    /* access modifiers changed from: private */
    public static void destroy() {
        try {
            Acp.getInstance(yContext).onDestroy();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void sensor(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.BODY_SENSORS).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass2 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void location(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.ACCESS_COARSE_LOCATION, Permission.ACCESS_FINE_LOCATION).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass3 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void audio(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.RECORD_AUDIO).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass4 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void cameraAndSD(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.CAMERA, Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass5 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void showPerDialog(Context context, String str, final OnClickResult onClickResult, boolean z) {
        if (context instanceof Application) {
            dialog = createSysDailog(context, R.layout._dialog_per_tip);
        } else {
            dialog = createDailog(context, R.layout._dialog_per_tip);
        }
        dialog.setCancelable(false);
        TextView textView = (TextView) dialog.findViewById(R.id.tv_per_detail);
        ImageView imageView = (ImageView) dialog.findViewById(R.id.bt_per_cancel);
        TextView textView2 = (TextView) dialog.findViewById(R.id.bt_per_sure);
        if (z) {
            textView.setGravity(3);
        } else {
            textView.setGravity(17);
        }
        textView.setText(str);
        imageView.setOnClickListener(new View.OnClickListener() {
            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass6 */

            public void onClick(View view) {
                YYPerUtils.dialog.dismiss();
                
                if (onClickResult != null) {
                    onClickResult.result(false);
                }
            }
        });
        textView2.setOnClickListener(new View.OnClickListener() {
            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass7 */

            public void onClick(View view) {
                YYPerUtils.dialog.dismiss();
                
                if (onClickResult != null) {
                    onClickResult.result(true);
                }
            }
        });
    }

    public static void showTip(Context context, String str, String str2, boolean z, final OnClickResult onClickResult) {
        if (context instanceof Application) {
            dialog = createSysDailog(context, R.layout._dialog_per_tip);
        } else {
            dialog = createDailog(context, R.layout._dialog_per_tip);
        }
        dialog.setCancelable(false);
        TextView textView = (TextView) dialog.findViewById(R.id.tv_per_detail);
        ImageView imageView = (ImageView) dialog.findViewById(R.id.bt_per_cancel);
        TextView textView2 = (TextView) dialog.findViewById(R.id.bt_per_sure);
        textView2.setText(str2);
        if (!z) {
            textView.setGravity(3);
        } else {
            textView.setGravity(17);
        }
        textView.setText(str);
        imageView.setOnClickListener(new View.OnClickListener() {
            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass8 */

            public void onClick(View view) {
                YYPerUtils.dialog.dismiss();
                
                if (onClickResult != null) {
                    onClickResult.result(false);
                }
            }
        });
        textView2.setOnClickListener(new View.OnClickListener() {
            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass9 */

            public void onClick(View view) {
                YYPerUtils.dialog.dismiss();
                
                if (onClickResult != null) {
                    onClickResult.result(true);
                }
            }
        });
    }

    public static Dialog createDailog(Context context, int i) {
        Dialog dialog2 = new Dialog(context);
        try {
            dialog2.requestWindowFeature(1);
            dialog2.setContentView(i);
            Window window = dialog2.getWindow();
            window.setBackgroundDrawableResource(R.drawable._dialog_bg);
            WindowManager.LayoutParams attributes = window.getAttributes();
            window.setGravity(17);
            attributes.width = -2;
            attributes.height = -2;
            window.setAttributes(attributes);
            dialog2.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dialog2;
    }

    public static Dialog createSysDailog(Context context, int i) {
        Dialog dialog2 = new Dialog(context);
        if (!hasOp()) {
            openOp();
        }
        try {
            dialog2.requestWindowFeature(1);
            dialog2.setContentView(i);
            Window window = dialog2.getWindow();
            window.setBackgroundDrawableResource(R.drawable._dialog_bg);
            WindowManager.LayoutParams attributes = window.getAttributes();
            window.setGravity(17);
            if (Build.VERSION.SDK_INT >= 26) {
                window.setType(2038);
            } else {
                window.setType(2003);
            }
            attributes.width = -2;
            attributes.height = -2;
            window.setAttributes(attributes);
            dialog2.show();
        } catch (Exception e) {
            e.printStackTrace();
            openOp();
        }
        return dialog2;
    }

    /* access modifiers changed from: private */
    public static void sdmi(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass10 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void sd(final OnPerListener onPerListener) {
        if (yContext == null) {
            onPerListener.result(false, "context is null");
        } else if (Build.VERSION.SDK_INT >= 30) {
            acpListener11 = new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass11 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                }
            };
            if (!hasSD()) {
                Intent intent = new Intent(yContext, AcpActivity11.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                yContext.startActivity(intent);
            } else if (onPerListener != null) {
                onPerListener.result(true, "");
            }
        } else {
            Log.d(TAG, "OnPerListener003");
            Acp.getInstance(yContext).request(new AcpOptions.Builder().setPermissions(Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass12 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void sdnormal(final OnPerListener onPerListener) {
        if (yContext == null) {
            onPerListener.result(false, "context is null");
            return;
        }
        Log.d(TAG, "OnPerListener003");
        Acp.getInstance(yContext).request(new AcpOptions.Builder().setPermissions(Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE).build(), new AcpListener() {
            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass13 */

            @Override // com.youyi.yypermissionlibrary.core.AcpListener
            public void onGranted() {
                
                if (onPerListener != null) {
                    onPerListener.result(true, "");
                }
                YYPerUtils.destroy();
            }

            @Override // com.youyi.yypermissionlibrary.core.AcpListener
            public void onDenied(List<String> list) {
                
                if (onPerListener != null) {
                    onPerListener.result(false, "");
                }
                YYPerUtils.destroy();
            }
        });
    }

    public static void sdAndPhone(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.READ_PHONE_STATE, Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass14 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void call(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.CALL_PHONE).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass15 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void sms(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.SEND_SMS).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass16 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void camera(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.CAMERA).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass17 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void image(final OnPerListener onPerListener) {
        if (yContext == null) {
            onPerListener.result(false, "context is null");
        } else if (Build.VERSION.SDK_INT >= 33) {
            Acp.getInstance(yContext).request(new AcpOptions.Builder().setPermissions("android.permission.READ_MEDIA_IMAGES").build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass18 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        } else {
            onPerListener.result(true, "");
        }
    }

    public static void cameraAndAudio(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.CAMERA, Permission.RECORD_AUDIO).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass19 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static void cameraAndAudioAnSD(final OnPerListener onPerListener) {
        Context context = yContext;
        if (context == null) {
            onPerListener.result(false, "context is null");
        } else {
            Acp.getInstance(context).request(new AcpOptions.Builder().setPermissions(Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE, Permission.CAMERA, Permission.RECORD_AUDIO).build(), new AcpListener() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass20 */

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onGranted() {
                    
                    if (onPerListener != null) {
                        onPerListener.result(true, "");
                    }
                    YYPerUtils.destroy();
                }

                @Override // com.youyi.yypermissionlibrary.core.AcpListener
                public void onDenied(List<String> list) {
                    
                    if (onPerListener != null) {
                        onPerListener.result(false, "");
                    }
                    YYPerUtils.destroy();
                }
            });
        }
    }

    public static boolean checkHasPermission(String... strArr) {
        Context context = yContext;
        if (context == null) {
            return false;
        }
        try {
            PackageManager packageManager = context.getPackageManager();
            int length = strArr.length;
            int i = 0;
            while (true) {
                boolean z = true;
                if (i >= length) {
                    return true;
                }
                if (packageManager.checkPermission(strArr[i], yContext.getPackageName()) != 0) {
                    z = false;
                }
                if (!z) {
                    return false;
                }
                i++;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean hasOp() {
        if (yContext == null) {
            return false;
        }
        if (Build.VERSION.SDK_INT >= 23) {
            return Settings.canDrawOverlays(yContext);
        }
        boolean z = Build.VERSION.SDK_INT < 19;
        if (z || Build.VERSION.SDK_INT < 19) {
            return z;
        }
        if (((AppOpsManager) yContext.getSystemService("appops")) == null) {
            return true;
        }
        try {
            Class<?> cls = Class.forName("android.content.Context");
            Field declaredField = cls.getDeclaredField("APP_OPS_SERVICE");
            declaredField.setAccessible(true);
            Object obj = declaredField.get(cls);
            if (!(obj instanceof String)) {
                return false;
            }
            Object invoke = cls.getMethod("getSystemService", String.class).invoke(yContext, (String) obj);
            Class<?> cls2 = Class.forName("android.app.AppOpsManager");
            Field declaredField2 = cls2.getDeclaredField("MODE_ALLOWED");
            declaredField2.setAccessible(true);
            if (((Integer) cls2.getMethod("checkOp", Integer.TYPE, Integer.TYPE, String.class).invoke(invoke, 24, Integer.valueOf(Binder.getCallingUid()), yContext.getPackageName())).intValue() == declaredField2.getInt(cls2)) {
                return true;
            }
            return false;
        } catch (Exception unused) {
            return false;
        }
    }

    public static void openOp() {
        if (yContext != null) {
            try {
                Intent intent = new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION");
                intent.setData(Uri.parse("package:" + yContext.getPackageName()));
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                yContext.startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static boolean hasSystemSetting() {
        if (yContext == null) {
            return false;
        }
        if (Build.VERSION.SDK_INT < 23 || Settings.System.canWrite(yContext)) {
            return true;
        }
        return false;
    }

    public static boolean hasNotic() {
        Context context = yContext;
        if (context == null) {
            return false;
        }
        try {
            ApplicationInfo applicationInfo = yContext.getApplicationInfo();
            String packageName = yContext.getApplicationContext().getPackageName();
            int i = applicationInfo.uid;
            Class<?> cls = Class.forName(AppOpsManager.class.getName());
            if (((Integer) cls.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class).invoke((AppOpsManager) context.getSystemService("appops"), Integer.valueOf(((Integer) cls.getDeclaredField(OP_POST_NOTIFICATION).get(Integer.class)).intValue()), Integer.valueOf(i), packageName)).intValue() == 0) {
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static void openNotic() {
        if (yContext != null) {
            try {
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 26) {
                    intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                    intent.putExtra("android.provider.extra.APP_PACKAGE", yContext.getPackageName());
                }
                if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 26) {
                    intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                    intent.putExtra("app_package", yContext.getPackageName());
                    intent.putExtra("app_uid", yContext.getApplicationInfo().uid);
                }
                if (Build.VERSION.SDK_INT < 21) {
                    intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                    intent.setData(Uri.fromParts(SettingPage.EXTRA_PKG, yContext.getPackageName(), null));
                }
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                yContext.startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
                Context context = yContext;
                gotoSettingByPackName(context, context.getPackageName());
            }
            new Intent("android.settings.APP_NOTIFICATION_SETTINGS").putExtra("android.provider.extra.APP_PACKAGE", yContext.getPackageName());
        }
    }

    public static void gotoSettingByPackName(Context context, String str) {
        try {
            Intent intent = new Intent();
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (Build.VERSION.SDK_INT >= 9) {
                intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                intent.setData(Uri.fromParts(SettingPage.EXTRA_PKG, str, null));
            } else if (Build.VERSION.SDK_INT <= 8) {
                intent.setAction("android.intent.action.VIEW");
                intent.setClassName("com.android.settings", "com.android.setting.InstalledAppDetails");
                intent.putExtra("com.android.settings.ApplicationPkgName", str);
            }
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getPhoneCompany() {
        String str = Build.MANUFACTURER;
        return (str == null || str.length() <= 0) ? "" : str.toLowerCase();
    }

    public static boolean isXiaoMi() {
        String str = Build.MANUFACTURER;
        return str != null && str.length() > 0 && str.toLowerCase().equals("xiaomi");
    }

    public static boolean hasAPPUse(Context context) {
        if (Build.VERSION.SDK_INT >= 23 && ((AppOpsManager) context.getSystemService("appops")).checkOpNoThrow("android:get_usage_stats", Process.myUid(), context.getPackageName()) != 0) {
            return false;
        }
        return true;
    }

    public static void openAPPUse(Context context) {
        try {
            Intent intent = new Intent("android.settings.USAGE_ACCESS_SETTINGS");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static boolean isIgnoringBatteryOptimizations() {
        PowerManager powerManager = (PowerManager) yContext.getSystemService("power");
        if (powerManager == null || Build.VERSION.SDK_INT < 23) {
            return false;
        }
        return powerManager.isIgnoringBatteryOptimizations(yContext.getPackageName());
    }

    public static void requestIgnoreBatteryOptimizations() {
        try {
            Intent intent = new Intent("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS");
            intent.setData(Uri.parse("package:" + yContext.getPackageName()));
            yContext.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void showActivity(String str) {
        try {
            yContext.startActivity(yContext.getPackageManager().getLaunchIntentForPackage(str));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void showActivity(String str, String str2) {
        try {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(str, str2));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            yContext.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static boolean isHuawei() {
        if (Build.BRAND == null) {
            return false;
        }
        if (Build.BRAND.toLowerCase().equals("huawei") || Build.BRAND.toLowerCase().equals("honor")) {
            return true;
        }
        return false;
    }

    public static void goHuaweiSetting() {
        try {
            showActivity("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");
        } catch (Exception unused) {
            showActivity("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.bootstart.BootStartActivity");
        }
    }

    public static boolean isXiaomi() {
        return Build.BRAND != null && Build.BRAND.toLowerCase().equals("xiaomi");
    }

    public static void goXiaomiSetting() {
        showActivity("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity");
    }

    public static boolean isOPPO() {
        return Build.BRAND != null && Build.BRAND.toLowerCase().equals("oppo");
    }

    public static void goOPPOSetting() {
        try {
            showActivity("com.coloros.phonemanager");
        } catch (Exception unused) {
            try {
                showActivity("com.oppo.safe");
            } catch (Exception unused2) {
                try {
                    showActivity("com.coloros.oppoguardelf");
                } catch (Exception unused3) {
                    showActivity("com.coloros.safecenter");
                }
            }
        }
    }

    public static boolean isVIVO() {
        return Build.BRAND != null && Build.BRAND.toLowerCase().equals("vivo");
    }

    public static void goVIVOSetting() {
        showActivity("com.iqoo.secure");
    }

    public static boolean isMeizu() {
        return Build.BRAND != null && Build.BRAND.toLowerCase().equals("meizu");
    }

    public static void goMeizuSetting() {
        showActivity("com.meizu.safe");
    }

    public static boolean isSamsung() {
        return Build.BRAND != null && Build.BRAND.toLowerCase().equals("samsung");
    }

    private void goSamsungSetting() {
        try {
            showActivity("com.samsung.android.sm_cn");
        } catch (Exception unused) {
            showActivity("com.samsung.android.sm");
        }
    }

    public static boolean isLeTV() {
        return Build.BRAND != null && Build.BRAND.toLowerCase().equals("letv");
    }

    public static void goLetvSetting() {
        showActivity("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity");
    }

    public static boolean isSmartisan() {
        return Build.BRAND != null && Build.BRAND.toLowerCase().equals("smartisan");
    }

    public static void goSmartisanSetting() {
        showActivity("com.smartisanos.security");
    }

    /* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARNING: Code restructure failed: missing block: B:18:0x0045, code lost:
        if (r0.equals("hornor") == false) goto L_0x001c;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static boolean hasBgOp() {
       return true;
    }

    public static boolean hasBgOp_HW() {
        if (yContext == null) {
            return false;
        }
        try {
            Class<?> cls = Class.forName("com.huawei.android.app.AppOpsManagerEx");
            Method declaredMethod = cls.getDeclaredMethod("checkHwOpNoThrow", AppOpsManager.class, Integer.TYPE, Integer.TYPE, String.class);
            String packageName = yContext.getPackageName();
            return ((Integer) declaredMethod.invoke(cls.newInstance(), new Object[]{(AppOpsManager) yContext.getSystemService("appops"), 100000, Integer.valueOf(Process.myUid()), packageName})).intValue() != 2;
        } catch (Exception unused) {
            return true;
        }
    }

    public static boolean hasBgOp_MI() {
        Context context = yContext;
        if (context == null) {
            return false;
        }
        AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService("appops");
        try {
            if (((Integer) appOpsManager.getClass().getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class).invoke(appOpsManager, 10021, Integer.valueOf(Process.myUid()), yContext.getPackageName())).intValue() == 0) {
                return true;
            }
            return false;
        } catch (Exception unused) {
            return false;
        }
    }

    public static boolean hasBgOp_VIVO() {
        String packageName = yContext.getPackageName();
        try {
            Cursor query = yContext.getContentResolver().query(Uri.parse("content://com.vivo.permissionmanager.provider.permission/start_bg_activity"), null, "pkgname = ?", new String[]{packageName}, null);
            if (query != null) {
                if (query.moveToFirst()) {
                    int i = query.getInt(query.getColumnIndex("currentstate"));
                    query.close();
                    if (i == 0) {
                        return true;
                    }
                    return false;
                }
                query.close();
            }
        } catch (Throwable unused) {
        }
        return false;
    }

    public static void image(final Context context, String str, final OnPerListener onPerListener) {
        if (getHasPerImage(context)) {
            image(onPerListener);
        } else {
            showPerDialog(context, str, new OnClickResult() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass21 */

                @Override // com.youyi.yypermissionlibrary.SDK.YYPerUtils.OnClickResult
                public void result(boolean z) {
                    if (z) {
                        YYPerUtils.image(new OnPerListener() {
                            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass21.AnonymousClass1 */

                            @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                            public void result(boolean z, String str) {
                                if (z) {
                                    YYPerUtils.setHasPerImage(context, true);
                                }
                                onPerListener.result(z, str);
                            }
                        });
                    }
                }
            }, false);
        }
    }

    public static void sd(final Context context, String str, final OnPerListener onPerListener) {
        if (getHasPerSD(context)) {
            sd(onPerListener);
        } else {
            showPerDialog(context, str, new OnClickResult() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass22 */

                @Override // com.youyi.yypermissionlibrary.SDK.YYPerUtils.OnClickResult
                public void result(boolean z) {
                    if (z) {
                        YYPerUtils.sd(new OnPerListener() {
                            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass22.AnonymousClass1 */

                            @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                            public void result(boolean z, String str) {
                                if (z) {
                                    YYPerUtils.setHasPerSD(context, true);
                                }
                                onPerListener.result(z, str);
                            }
                        });
                    }
                }
            }, false);
        }
    }

    public static void sdMI(final Context context, String str, final OnPerListener onPerListener) {
        if (getHasPerSD(context)) {
            sdmi(onPerListener);
        } else {
            showPerDialog(context, str, new OnClickResult() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass23 */

                @Override // com.youyi.yypermissionlibrary.SDK.YYPerUtils.OnClickResult
                public void result(boolean z) {
                    if (z) {
                        YYPerUtils.sdmi(new OnPerListener() {
                            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass23.AnonymousClass1 */

                            @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                            public void result(boolean z, String str) {
                                if (z) {
                                    YYPerUtils.setHasPerSD(context, true);
                                }
                                onPerListener.result(z, str);
                            }
                        });
                    }
                }
            }, false);
        }
    }

    public static void sensor(final Context context, String str, final OnPerListener onPerListener) {
        if (getHasPerSensor(context)) {
            sensor(onPerListener);
        } else {
            showPerDialog(context, str, new OnClickResult() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass24 */

                @Override // com.youyi.yypermissionlibrary.SDK.YYPerUtils.OnClickResult
                public void result(boolean z) {
                    if (z) {
                        YYPerUtils.sensor(new OnPerListener() {
                            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass24.AnonymousClass1 */

                            @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                            public void result(boolean z, String str) {
                                if (z) {
                                    YYPerUtils.setHasPerSensor(context, true);
                                }
                                onPerListener.result(z, str);
                            }
                        });
                    }
                }
            }, false);
        }
    }

    public static void audio(final Context context, String str, final OnPerListener onPerListener) {
        if (getHasPerAudio(context)) {
            audio(onPerListener);
        } else {
            showPerDialog(context, str, new OnClickResult() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass25 */

                @Override // com.youyi.yypermissionlibrary.SDK.YYPerUtils.OnClickResult
                public void result(boolean z) {
                    if (z) {
                        YYPerUtils.audio(new OnPerListener() {
                            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass25.AnonymousClass1 */

                            @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                            public void result(boolean z, String str) {
                                if (z) {
                                    YYPerUtils.setHasPerAudio(context, true);
                                }
                                onPerListener.result(z, str);
                            }
                        });
                    }
                }
            }, false);
        }
    }

    public static void camera(final Context context, String str, final OnPerListener onPerListener) {
        if (getHasPerCamera(context)) {
            camera(onPerListener);
        } else {
            showPerDialog(context, str, new OnClickResult() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass26 */

                @Override // com.youyi.yypermissionlibrary.SDK.YYPerUtils.OnClickResult
                public void result(boolean z) {
                    if (z) {
                        YYPerUtils.camera(new OnPerListener() {
                            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass26.AnonymousClass1 */

                            @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                            public void result(boolean z, String str) {
                                if (z) {
                                    YYPerUtils.setHasPerCamera(context, true);
                                }
                                onPerListener.result(z, str);
                            }
                        });
                    }
                }
            }, false);
        }
    }

    public static void call(final Context context, String str, final OnPerListener onPerListener) {
        if (getHasPerCall(context)) {
            call(onPerListener);
        } else {
            showPerDialog(context, str, new OnClickResult() {
                /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass27 */

                @Override // com.youyi.yypermissionlibrary.SDK.YYPerUtils.OnClickResult
                public void result(boolean z) {
                    if (z) {
                        YYPerUtils.call(new OnPerListener() {
                            /* class com.youyi.yypermissionlibrary.SDK.YYPerUtils.AnonymousClass27.AnonymousClass1 */

                            @Override // com.youyi.yypermissionlibrary.SDK.OnPerListener
                            public void result(boolean z, String str) {
                                if (z) {
                                    YYPerUtils.setHasPerCall(context, true);
                                }
                                onPerListener.result(z, str);
                            }
                        });
                    }
                }
            }, false);
        }
    }

    public static void setHasPerImage(Context context, boolean z) {
        context.getSharedPreferences("DataUtil_1", 0).edit().putBoolean("setHasPerImage", z).commit();
    }

    public static boolean getHasPerImage(Context context) {
        return context.getSharedPreferences("DataUtil_1", 0).getBoolean("setHasPerImage", false);
    }

    public static void setHasPerSD(Context context, boolean z) {
        context.getSharedPreferences("DataUtil_1", 0).edit().putBoolean("setHasPerSD", z).commit();
    }

    public static boolean getHasPerSD(Context context) {
        return context.getSharedPreferences("DataUtil_1", 0).getBoolean("setHasPerSD", false);
    }

    public static void setHasPerSensor(Context context, boolean z) {
        context.getSharedPreferences("DataUtil_1", 0).edit().putBoolean("setHasPerSensor", z).commit();
    }

    public static boolean getHasPerSensor(Context context) {
        return context.getSharedPreferences("DataUtil_1", 0).getBoolean("setHasPerSensor", false);
    }

    public static void setHasPerAudio(Context context, boolean z) {
        context.getSharedPreferences("DataUtil_1", 0).edit().putBoolean("setHasPerAudio", z).commit();
    }

    public static boolean getHasPerAudio(Context context) {
        return context.getSharedPreferences("DataUtil_1", 0).getBoolean("setHasPerAudio", false);
    }

    public static void setHasPerCamera(Context context, boolean z) {
        context.getSharedPreferences("DataUtil_1", 0).edit().putBoolean("setHasPerCamera", z).commit();
    }

    public static boolean getHasPerCamera(Context context) {
        return context.getSharedPreferences("DataUtil_1", 0).getBoolean("setHasPerCamera", false);
    }

    public static void setHasPerCall(Context context, boolean z) {
        context.getSharedPreferences("DataUtil_1", 0).edit().putBoolean("setHasPerCall", z).commit();
    }

    public static boolean getHasPerCall(Context context) {
        return context.getSharedPreferences("DataUtil_1", 0).getBoolean("setHasPerCall", false);
    }
}
